import { baseScene } from "../tool/baseScene";
import * as fs from "fs";
import * as path from "path";
import { BaseManager } from "./BaseManager";

export class SceneManager extends BaseManager {
    scenes: Map<string, baseScene> = new Map();
    
    constructor() {
        super();
        this.scenes = new Map();
        // SceneManager不依赖其他管理器
        this.dependencies = [];
    }
    
    async init() {
        this.log('info', '开始初始化场景管理器');
        
        try {
            const sceneDir = path.resolve(__dirname, '../../scene');
            const scenes = fs.readdirSync(sceneDir);
            
            for (const scene of scenes) {
                const sceneModule = await import(`../../scene/${scene}`);
                sceneModule.default.scene = scene.split('.')[0];
                this.addScene(sceneModule.default);
            }
            
            this.markAsInitialized();
        } catch (error) {
            this.handleError(error, '场景管理器初始化');
        }
    }
    addScene(scene:baseScene){
        this.scenes.set(scene.scene,scene);
        console.log(`添加场景：${scene.scene}`);
    }
    getScene(scene:string = 'default'){
        return this.scenes.get(scene);
    }
    
}
export default new SceneManager();